using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.Shell.Interop;
using System.ComponentModel;

namespace Ferpect.GameComponents.Design
{
    public class Texture2DConverter : StringConverter
    {
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            if (context != null)
            {
                List<string> textures = new List<string>();
                EnvDTE.ProjectItem projectItem = context.GetService(typeof(EnvDTE.ProjectItem)) as EnvDTE.ProjectItem;
                if (projectItem != null)
                {
                    EnvDTE.Project codeProject = projectItem.ContainingProject;
                    IVsHierarchy hierarchy = DesignerUtilities.GetHierarchyForProject(codeProject);
                    IList<IVsHierarchy> nestedHierarchies = DesignerUtilities.GetNestedContentProjects(hierarchy);
                    try
                    {
                        foreach (IVsHierarchy nestedHierarchy in nestedHierarchies)
                        {
                            DesignerUtilities.GetTexture2DAssetNames(nestedHierarchy, textures);
                        }
                    }
                    catch (Exception e)
                    {
                        textures.Add(e.Message);
                    }
                }
                return new StandardValuesCollection(textures);
            }
            return base.GetStandardValues(context);
        }

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }
    }
}
